package com.lagou.service;

import com.lagou.dao.AuthCodeDao;
import com.lagou.edu.pojo.LagouAuthCode;
import com.lagou.edu.pojo.LagouToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.Optional;

@Service
@Transactional
public class AuthCodeService {

    @Autowired
    private AuthCodeDao authCodeDao;

    public void insert(LagouAuthCode lagouAuthCode) {
        authCodeDao.save(lagouAuthCode);
    }

    public Optional<LagouAuthCode> fiddByEmail(String email) {
        LagouAuthCode lagouAuthCode = new LagouAuthCode();
        lagouAuthCode.setEmail(email);
        Example<LagouAuthCode> example = Example.of(lagouAuthCode);
        return authCodeDao.findOne(example);
    }
}
